package com.wwwarehouse.usercenter.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.bean.authoritydistribute.AuthorityWrapItemBean;
import com.wwwarehouse.usercenter.bean.business_relationship.BRCFDTagsBean;
import com.wwwarehouse.usercenter.bean.business_relationship.BRCustomerFileDetailBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : mundane
 * @time : 2017/9/20 14:14
 * @description :
 * @file : AuthorityDistributeRvAdapter.java
 */
public class BRCFDTagsUpdateAdapter extends RecyclerView.Adapter<BRCFDTagsUpdateAdapter.BRCFDTagsUpdateAdapterHolder> {

    private final int mRvHeight;
    private BRCFDTagsBean mDataList;
    private Context mContext;
    private ArrayList<BRCustomerFileDetailBean.TagsBean> tagIds;

    public interface OnItemClickListener{
        void onButtonClicked(int position);

    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    public BRCFDTagsUpdateAdapter(BRCFDTagsBean dataList, int height,ArrayList<BRCustomerFileDetailBean.TagsBean> tagIds) {
        this.mDataList = dataList;
        mRvHeight = height;
        this.tagIds = tagIds;
    }

    @Override
    public BRCFDTagsUpdateAdapterHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_pr_user_card, parent, false);
        return new BRCFDTagsUpdateAdapterHolder(view);
    }

    @Override
    public void onBindViewHolder(final BRCFDTagsUpdateAdapterHolder holder, final int position) {
        ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
        params.height = (int) (mRvHeight * 0.85 / 9);
        holder.itemView.setLayoutParams(params);
        BRCFDTagsBean.ListBean listBean = mDataList.getList().get(position);
        holder.mBtn.setText(listBean.getTagName());
        if (mOnItemClickListener != null) {
            holder.mBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onButtonClicked(position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return mDataList == null ? 0 : mDataList.getList().size();
    }

    static class BRCFDTagsUpdateAdapterHolder extends RecyclerView.ViewHolder {

        public Button mBtn;

        public BRCFDTagsUpdateAdapterHolder(View itemView) {
            super(itemView);
            mBtn = (Button) itemView.findViewById(R.id.btn);
        }
    }
}
